import PopupManager from "../../../core/PopupManager";
import ResManager from "../../../core/ResManager";
import { ResType } from "../../../net/Commond";
import { BattleTest } from "../../data/BattleTest";
import { ResPath } from "../../data/CFCommon";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ItemHeroPos extends cc.Component {

    @property(cc.Node)
    heroNode: cc.Node = null;

    @property(cc.Sprite)
    heroIcon: cc.Sprite = null;

    heroId: number = 0;

    protected onLoad(): void {
        this.node.on(cc.Node.EventType.TOUCH_END, this.onClick, this);
    }

    init(heroId: number) {
        this.heroId = heroId;
        this.heroNode.active = true;
        let heroData = BattleTest.ins().getHeroConfigData(heroId);
        if (heroData) {
            ResManager.ins().loadSingle(heroData.heroIcon, ResType.image, ResPath.heroicon, (asset) => {
                this.heroIcon.spriteFrame = asset;
            }, this.node);
        }
    }

    hideHeroNode() {
        this.heroId = 0
        this.heroIcon.spriteFrame = null;
        this.heroNode.active = false;
    }

    onClick() {
        if (this.heroId > 0) {
            PopupManager.show('prefabs/popups/PopupCardInfo',this.heroId,{immediately:true});
        }
    }
}
